<?php

namespace App\Ship\Parents\Repositories;

use Apiato\Core\Abstracts\Repositories\Repository as AbstractRepository;

abstract class Repository extends AbstractRepository
{
    /**
     * Boot up the repository, pushing criteria.
     */
    public function boot()
    {
        parent::boot();
    }

    /**
     * Unset Searchable Fields
     *
     * @param mixed ...$keys
     * @return self
     */
    public function unsetFieldsSearchableKeys(...$keys): self
    {
        $this->fieldSearchable = array_diff_key($this->fieldSearchable, $keys);
        return $this;
    }

    /**
     * Eager load relations on the model.
     *
     * @param array|string $relations
     * @return $this
     */
    public function load($relations): self
    {
        $this->model = $this->model->load($relations);
        return $this;
    }

    /**
     * Add a relationship count / exists condition to the query.
     *
     * @param $relation
     * @param string $boolean
     * @param null $callback
     * @return $this
     */
    public function doesntHave($relation, string $boolean = 'and', $callback = null): self
    {
        $this->model = $this->model->doesntHave($relation, $boolean, $callback);
        return $this;
    }

    /**
     * Add a relationship count / exists condition to the query with an "or".
     *
     * @param $relation
     * @return $this
     */
    public function orDoesntHave($relation): self
    {
        $this->model = $this->model->orDoesntHave($relation);
        return $this;
    }

    /**
     * Load relation with closure
     *
     * @param $relation
     * @param null $callback
     * @return $this
     */
    public function orWhereHas($relation, $callback = null): self
    {
        $this->model = $this->model->orWhereHas($relation, $callback);

        return $this;
    }
}
